﻿#建议保存编码为：bom头 + utf8

param
(
	[ValidateNotNullOrEmpty()]
	[Alias("choice")][array]$选项 = @('选择1，立即开始学习powershell','选择2，立即删库跑路','选择3，powershell脚本之巅出品','选择4，群号=183173532','选择5，值->$Global:单选')
)


#导入模块，加载dll
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
	Add-Type -Path "${PSScriptRoot}/Terminal.Gui.ps51.dll" -ErrorAction Stop
}
else
{
	Add-Type -Path "${PSScriptRoot}/Terminal.Gui.dll" -ErrorAction Stop
}

#region code

#endregion code

#region tui
[Terminal.Gui.Application]::Init()
$Window = [Terminal.Gui.Window]::new()
$Window.Title = "PowerShell 单选 tui图形界面例子。按 Ctrl + Q 退出"
$Window.Width = [Terminal.Gui.Dim]::Percent(40)
$Window.Height = [Terminal.Gui.Dim]::Percent(30)
$Window.x = [Terminal.Gui.Pos]::Center()
$Window.y = [Terminal.Gui.Pos]::Center()

$ListView = [Terminal.Gui.ListView]::new()
$ListView.Width = [Terminal.Gui.Dim]::Fill()
$ListView.Height = [Terminal.Gui.Dim]::Fill()
$ListView.SetSource($选项)
$ListView.add_SelectedItemChanged( {
		$Global:单选 = $选项[$ListView.SelectedItem]
	})

$ListView.add_KeyPress( {
		param($arg)
		if ($arg.KeyEvent.Key.ToString() -eq "enter")
		{
			[Terminal.Gui.Application]::Shutdown()
		}
	})
$Window.Add($ListView)
#-------------------------------------------

#endregion tui
[Terminal.Gui.Application]::Top.Add($Window)
[void][Terminal.Gui.Application]::Run()
[void][Terminal.Gui.Application]::Shutdown()
